package com.tianhui.consignortwofei.utils.shuiyin;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.tianhui.consignortwofei.utils.Util;

/**
 * @author fei
 * @date 2024/3/25
 * @description
 */
public class WatermarkBackgroundView extends View {

    private Paint paint;
    private String watermarkText = "WATERMARK";

    public WatermarkBackgroundView(Context context) {
        super(context);
        init();
    }

    public WatermarkBackgroundView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(Color.GRAY);
        paint.setAlpha(100); // 设置水印的透明度
        paint.setTextSize(60);
        paint.setAntiAlias(true);
        String shuiYinText = Util.getShuiYinText();
        watermarkText=shuiYinText;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 绘制水印背景
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);

        // 绘制水印文字
        paint.setColor(Color.WHITE);
        canvas.drawText(watermarkText, getWidth() / 4, getHeight() / 2, paint);
    }
}
